package com.jiukuaidao.zhulin.module.commodity.presenter;

import com.jiukuaidao.library.net.MyRetroCallBack;
import com.jiukuaidao.library.util.LogUtil;
import com.jiukuaidao.zhulin.api.ApiGetSortCatList;
import com.jiukuaidao.zhulin.entity.ApiSortCatList;
import com.jiukuaidao.zhulin.module.BasePresenter;
import com.jiukuaidao.zhulin.module.commodity.contract.SortContract;

import java.util.List;

/**
 * Author : H_Joker
 * Date : 2016/5/27
 * Description :
 */
public class SortPresenter extends BasePresenter<SortContract.View, SortContract.Model> implements SortContract.Presenter {


    public SortPresenter(SortContract.Model repository, SortContract.View view) {
        super(repository, view);
    }

    @Override
    public void start() {

    }

    @Override
    public void loadCatList(String latitude, String longitude, String city) {
        mRepository.loadData(new ApiGetSortCatList<>(city, longitude, latitude, new MyRetroCallBack<ApiSortCatList>() {
            @Override
            public void onSuccess(ApiSortCatList result, String errorCode, String msg) {
                if (result != null) {
                    mRepository.setCateList(result.list);
                    mView.createFragments();
                }
            }

            @Override
            public void onFail(ApiSortCatList result, String errorCode, String msg) {
                LogUtil.log(msg);
            }

            @Override
            public void onError(Throwable t, int resCode, String msg) {
                LogUtil.log(msg);
            }
        }));
    }

    @Override
    public List<String> getCateNames() {
        return mRepository.getCateNames();
    }

    @Override
    public void setCatNames(List<String> names) {
        mRepository.setCatNames(names);
    }

    @Override
    public List<ApiSortCatList.ApiSortCateListItem> getCateList() {
        return mRepository.getCateList();
    }


}
